using UnityEngine;

namespace GGPhysics
{
	public struct Collision
	{
		public CollidingBody body1;

		public CollidingBody body2;

		public bool isColliding;

		public Vector3 collisionPoint;

		public float timeOfImpact;

		public bool isCanceled;

		public static Collision indentity
		{
			get
			{
				Collision result = default(Collision);
				result.body1 = CollidingBody.identity;
				result.body2 = CollidingBody.identity;
				result.isColliding = true;
				return result;
			}
		}

		public PhysicsBody collidingBody1
		{
			get
			{
				return body1.body;
			}
			set
			{
				body1.body = value;
			}
		}

		public PhysicsBody collidingBody2
		{
			get
			{
				return body2.body;
			}
			set
			{
				body2.body = value;
			}
		}

		public Vector3 collidingBody1PositionAtCollision
		{
			get
			{
				return body1.transformAtCollision.position;
			}
			set
			{
				body1.transformAtCollision.position = value;
			}
		}

		public Vector3 collidingBody2PositionAtCollision
		{
			get
			{
				return body2.transformAtCollision.position;
			}
			set
			{
				body2.transformAtCollision.position = value;
			}
		}

		public void SetMotionsBeforeCollisions()
		{
			body1.SetMotionBeforCollision();
			body2.SetMotionBeforCollision();
		}

		public CollidingBody CollidingBodyForTag(string tag)
		{
			if (collidingBody1.tag == tag)
			{
				return body1;
			}
			return body2;
		}

		public bool ContainsTag(string tag)
		{
			return collidingBody1.tag == tag || collidingBody2.tag == tag;
		}

		public CollidingBody CollidingBodyForBody(PhysicsBody body)
		{
			return (collidingBody1 != body) ? body2 : body1;
		}

		public CollidingBody OtherCollidingBody(PhysicsBody body)
		{
			return (collidingBody1 != body) ? body1 : body2;
		}

		public bool ContainsBody(PhysicsBody body)
		{
			return collidingBody1 == body || collidingBody2 == body;
		}

		public PhysicsBody OtherBody(PhysicsBody body)
		{
			return (collidingBody1 != body) ? collidingBody1 : collidingBody2;
		}

		public void ResolveCollision()
		{
			CollisionResolution.ResolveCollision3(ref this);
		}

		public void ResolveCollisionAndApply()
		{
			CollisionResolution.ResolveCollision3(ref this);
			body1.ApplyResolution();
			body2.ApplyResolution();
		}
	}
}
